@extends('admin.common.main')
@section('header')
  {{--  <link rel="stylesheet" href="/admin/js/bootstrap.min.css">--}}
  <link rel="stylesheet" href="/admin/js/pagination.css">

@endsection

@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 用户管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="text-c"> 日期范围：
            <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin" class="input-text Wdate" style="width:120px;">
            -
            <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:120px;">
            <input type="text" class="input-text" style="width:250px" placeholder="输入会员名称、电话、邮箱" id="" name="">
            <button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>

                <a href="{{route('admin.user.add')}}"  class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加用户</a></span> <span class="r">共有数据：<strong>88</strong> 条</span> </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg table-sort">
                <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="80">ID</th>
                    <th width="100">用户名</th>
                    <th width="40">性别</th>
                    <th width="90">手机</th>
                    <th width="150">邮箱</th>
                    <th width="">地址</th>
                    <th width="130">加入时间</th>
                    <th width="70">状态</th>
                    <th width="200">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $key=>$val)
                    <tr class="text-c">
                        <td>
                            @if(auth()->id() != $val['id'] )
                            <input type="checkbox" value="1" name="">
                            @else
                                <input type="checkbox" value="1" name="" disabled>

                                @endif
                        </td>
                        <td>{{$val['id']}}</td>
                        <td><u style="cursor:pointer" class="text-primary" onclick="member_show('张三','member-show.html','10001','360','400')">{{$val['truename']}}</u></td>
                        <td>{{$val['sex']}}</td>
                        <td>{{$val['phone']}}</td>
                        <td>{{$val['email']}}</td>
                        <td class="text-l">北京市 海淀区</td>
                        <td>{{$val['created_at']}}</td>
                        <td class="td-status"><span class="label label-success radius">已启用</span></td>
                        <td class="td-manage">
                            @if(!$val['deleted_at'])
                                <a href="{{route('admin.user.role',$val)}}"  class="label label-primary radius byRole">分配角色</a>
                            @endif
                           {{--<a href="{{route('admin.user.role',$val)}}"  class="label label-primary radius " hidden="hidden">分配角色</a>--}}
                            <a href="javascript:;" onclick="member_del(this,'1')" class="label label-default radius" style="text-decoration:none">编辑</a>


                            @if(auth()->id() != $val['id'] )

                                @if(!$val['deleted_at'])
                                    {{-- 此时为字符串，强转为 html --}}
                                    {!! $val->delBtn('admin.user.del') !!}
                                   {{-- {{$val->delBtn('admin.user.del')}}--}}
                                 @else
                                         {!! $val->resBtn('admin.user.restore') !!}

                               @endif
                            @endif
                        </td>
                    </tr>

                @endforeach
                </tbody>
            </table>

            {{$data->links()}}
        </div>
    </div>

@endsection


@section('js')
    <script type="text/javascript">


        /*用户-删除-恢复*/
        $('.ones').click(function () {

            let url= $(this).attr('href');

            let _that=$(this);

            if($(this).hasClass("delBtn")){
                layer.confirm('确认要删除吗？',function(index){
                    $.ajax({
                        type: 'DELETE',
                        data:{ _token:"{{csrf_token()}}" },
                        url:url,
                        dataType: 'json',
                        success: data =>{

                            _that.attr({ href: "{{route('admin.user.restore',['id'=>$val['id']])}}", class: "ones label label-warning radius resBtn" }).text("恢复");

                             _that.closest('td').find("a:first-child").hide();  // 不占位 隐藏   通过上级找下级
                            //  _that.prev().prev().hide();  //找上上个 节点元素
                            layer.msg(data.msg,{icon:1,time:1000});
                           //location.reload()
                        }
                    });

                });

            }

            if($(this).hasClass("resBtn")){
                $.ajax({
                    type: 'get',
                    url:url,
                    dataType: 'json',
                    success: data =>{
                        _that.attr({ href: "{{route('admin.user.del',['id'=>$val['id']])}}", class: "ones label label-danger radius delBtn" }).text("删除");

                        //如果有分配角色按钮
                        if(_that.hasClass("byRole")){
                            //    $('.byRole').css("visibility","visible");   占位隐藏 对应的展示
                            _that.closest('td').find("a:first-child").show();
                        }else{
                            //没有
                            _that.closest('td').prepend('<a href="{{route('admin.user.role',$val)}}" class="label label-primary radius byRole">分配角色</a>');
                        }

                        layer.msg(data.msg,{icon:1,time:1000});
                    }
                });
            }


            return false
        });



        /*用户-恢复*/
      /*  $('.resBtn').click(function () {

            let url= $(this).attr('href');


            let _that=$(this);

                $.ajax({
                    type: 'get',
                    url:url,
                    dataType: 'json',
                    success: data =>{
                        _that.attr({ href: "{{--{{route('admin.user.del',['id'=>$val['id']])}}--}}", class: "label label-warning radius delBtn" }).text("删除");

                        layer.msg(data.msg,{icon:1,time:1000});
                    }
                });



            return false
        });
*/

    </script>

@endsection

